let situation = '';
import env from "../../utils/env";

Page({
  /**
   * 页面的初始数据
   */
  data: {
    situationArr: [
      { text: '一寸蓝底', value: '0' },
      { text: '一寸白底', value: '1' },
      { text: '一寸红底', value: '2' },
      { text: '二寸蓝底', value: '3' },
      { text: '二寸白底', value: '4' },
      { text: '二寸红底', value: '5' },
      { text: '社保卡', value: '6' },
      { text: '驾驶证', value: '7' },
      { text: '身份证', value: '8' },
      { text: '护照', value: '9' },
      { text: '大学生图像信息采集', value: '10' },
      { text: '研究生考试', value: '11' },
      { text: '英语四六级', value: '12' },
      { text: '高考报名', value: '13' },
      { text: '成人自考', value: '14' },
      { text: '国家公务员考试', value: '15' },
      { text: '普通话水平测试', value: '16' },
      { text: '港澳通行证', value: '17' }
    ],
    type: '',
  },
  //岗位
  bindPickerChangeAge: function (e) {
    this.setData({
      type: e.detail.value
    })
  },
  validate() {
    if (this.data.type != '') {
      return true;
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '请选择一个证件照类型',
        showCancel: false,
      })
      return false;
    }
  },
  onLoad() {
    this.setData({
      logs: (wx.getStorageSync('logs') || []).map(log => {
        return {
          date: util.formatTime(new Date(log)),
          timeStamp: log
        }
      })
    })
  },
  goTakePhoto: function () {
    if (this.validate()) {
      wx.navigateTo({
        //目的页面地址
        url: '/pages/takePhoto/index?type=' + this.data.type,
        success: function (res) {
        }
      })
    }
  },
  goAlbum: function () {
    var that = this
    if (this.validate()) {
      wx.chooseMedia({
        count: 1,
        sizeType:['compressed'],
        mediaType: ['image'],
        sourceType: ['album'],
        maxDuration: 30,
        success(res) {
          wx.showToast({ title: '靓照处理中，请稍后', icon: 'loading', duration: 3000 });
          var fileUrl = res.tempFiles[0].tempFilePath;
          wx.navigateTo({
            //目的页面地址
            url: '/pages/preview/index?src=' + fileUrl+'&type='+that.data.type,
          })
        }
      })
    }
  }
})